var path ;

$(function(){
	getPath(path) ;
	changeVerifyImageURL() ;
});

//获得项目根路径
function getPath(path) {this.path = path ;}

/** 验证用户登录 */
function checkLogin() {
	
	var username = $("#username").val();
	var passwd = $("#passwd").val();
	var msg = $("#msg") ;
	msg.empty() ;
	msg.css("color","red") ;
	if("" != username && "" != passwd) {
		
		var url = path + "/loginSystem!loginCheck.action?d="+new Date().getTime() ;
		var senddata = {"account.username":username,"account.password":passwd} ;
		
		msg.text("正在验证账号...") ;
		
		$.post(url,senddata,function(json,textStatus){
			
			if("success" == textStatus) {
				var data = eval(json);
				
				if(null == data.account) {
					msg.text("该账号不存在，无法登录！") ;
				} else {
					if(true == data.account.state) {
						msg.css("color","green") ;
						msg.text("账号验证成功，正在登入系统...") ;
						//var empRealname = data.account.emp.empRealname ;
						//var deptName = data.account.emp.dept.deptName ;
						//setTimeout("window.location.href=path + '/web_manager/index.jsp?empRealname="+encodeURIComponent(empRealname)+"&deptName="+encodeURIComponent(deptName)+"'", 1000) ;
						setTimeout("window.location.href=path + '/web_manager/page/manager_index.jsp'", 1000) ;
					} else {
						msg.text("账号未激活，请与管理员联系！") ;
					}
				}
			} else {
				msg.text("访问页面出错！") ;
			}
		},"json");
	} else {
		msg.text("账号不允许为空！") ;
	}
}

/**
 * 验证码
 * @return
 */
function changeVerifyImageURL() {
	$("#verifyImage").attr("src","/sugar/verifyImgAction.action?d="+new Date().getTime());
	$("#verifyImage").show();
}


/** 清空登录输入框内容 */
function resetLogin(){$("#username").val("");$("#passwd").val("");}

/** 去除所有空格 */
function ignoreSpaces(string) {
	var temp = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
		temp += splitstring[i];
	return temp;
}

